<layout name="Iflayout"/>

<script type="text/javascript">
    $(function(){

        //选中全部子级
        $('input[level=1]').click(function(){

            var checked = $(this).prop('checked');
            var inputs = $(this).parents('.panel').find('.panel-body input');
            if (checked) {
                inputs.prop('checked', true);
            }else {
                inputs.prop('checked', false);
            }

        });
        //选中全部子级
        $('input[level=2]').click(function(){

            var checked = $(this).prop('checked');
            var parent = $(this).parents('.panel:eq(0)');
            var topParent = parent.parents('.panel:eq(0)');
            if (checked) {
                parent.find('.panel-body input').prop('checked', true);
                topParent.find('input[level=1]').prop('checked', true);
            }else {
                parent.find('.panel-body input').prop('checked', false);
                topParent.find('input[level=1]').prop('checked', false);
            }

        });

        //选中父级
        $('input[level=3]').click(function(){

            var checked = $(this).prop('checked');
            var parent = $(this).parents('.panel:eq(0)');
            var topParent = parent.parents('.panel:eq(0)');
            if (checked) {
                parent.find('.panel-heading input').prop('checked', true);
                topParent.find('input[level=1]').prop('checked', true);
            }

        });



    });

</script>

<div class="xyh-content">

    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header"><em class="glyphicon glyphicon-cloud-upload"></em>
                权限设置
            </h3>
        </div>

    </div>

    <div class="row margin-botton">
        <div class="col-lg-12">
            <div class="btn-group btn-group-md">
                <button class="btn btn-primary" type="button" onclick="goUrl('{:U(\'Role/index\')}')">
                    <em class="glyphicon glyphicon-chevron-left"></em>
                    返回
                </button>
                <button class="btn btn-info" type="button" onclick="doGoSubmit('{:U(\'Access/add\')}', 'formAccess')">
                    <em class="glyphicon glyphicon-saved"></em>
                    更新权限
                </button>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <form method="post" action="" id="formAccess">
                <input type="hidden" name="rid" value="{$role_id}"/>
                <foreach name="res" item="v">
                <div class="panel panel-info">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-8">
                                <h3 class="panel-title">
                                    <input type="checkbox" name="access[]" value="{$v.id}_{$v.level}" level="1" {$v[select]?'checked':'mm'}/> {$v.title}</h3>
                            </div>
                        </div>

                    </div>
                    <div class="panel-body xyh-panel-body">
                        <foreach name="v['son']" item="vv">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <div class="row">
                                    <div class="col-xs-8">
                                        <h3 class="panel-title">
                                            <input type="checkbox" name="access[]" value="{$vv.id}_{$vv.level}" level="2" {$vv[select]?'checked':'mm'} />{$vv.title}</h3>
                                    </div>
                                </div>

                            </div>
                            <div class="panel-body">
                                <label class="checkbox-inline">
                                    <foreach name="vv['son']" item="vvv">
                                    <input type="checkbox" name="access[]" value="{$vvv.id}_{$vvv.level}" level="3" {$vvv[select]?'checked':'mm'} />
                                    <span class="label label-primary">{$vvv.title}</span>
                                </label>&nbsp;&nbsp;</foreach>
                            </div></div>
                            </foreach>
                    </div>
                    <div class="panel-body xyh-panel-body">
                    </div>
                </div>
                    </foreach>
                </form>
